package com.netease.homework.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.netease.homework.meta.Selled;

/**
 * 
 * @author smart
 * @时间 2019年3月8日
 * @描述 已售出信息
 */
@Component
public interface ISelledDao {

	/**
	 * 
	 * @描述 根据id获取单个售出
	 * @param id
	 * @return 售出信息
	 */
	@Select("select * from selled where id=#{id}")
	@Results({
        @Result(
       		 property = "commodity",
       		 column = "commodity_id",
       		 one = @One(select = "com.netease.homework.dao.ICommodityDao.getCommById")
       		 )
	})
	public Selled getSelledById(Integer id);

	/**
	 * 
	 * @描述 添加售出信息
	 * @param selled
	 * @return 
	 */
	@Insert("INSERT INTO `selled` (`user_id`, `commodity_id`, `time`, `number`, `price`) "
			+  " VALUES (#{userId},#{commodity.id}, #{time}, #{number}, #{price}) ")
	public int addSelled(Selled selled);

	/**
	 * 
	 * @描述 获取所有售出信息（未使用userName）
	 * @param userName
	 * @return 售出列表
	 */
	@Select("select * from selled")
	@Results({
	         @Result(
	        		 property = "commodity",
	        		 column = "commodity_id",
	        		 one = @One(select = "com.netease.homework.dao.ICommodityDao.getCommById")
	        		 )
	})
	public List<Selled> getSelledByUserName(String userName);

	/**
	 * 
	 * @描述 根据商品id获取售出
	 * @param id
	 * @return 售出信息
	 */
	@Select("select * from selled where commodity_id=#{id}")
	public Selled getSelledByCommId(Integer id);
	
}
